<template>
  <div class="home-container">
    <div class="welcome-section">
      <h2>欢迎使用微前端平台</h2>
      <p>基于 qiankun + workspaces 微前端架构解决方案，支持工作区组件/模块共享、多应用独立开发、独立部署、协同运行。</p>
    </div>

    <div class="features-section">
      <div class="feature-card">
        <div class="feature-icon">🎯</div>
        <h3>独立开发</h3>
        <p>每个微应用可以独立开发、独立测试，不影响其他应用。</p>
      </div>

      <div class="feature-card">
        <div class="feature-icon">🚀</div>
        <h3>独立部署</h3>
        <p>各微应用可以单独部署上线，缩短迭代周期，降低风险。</p>
      </div>

      <div class="feature-card">
        <div class="feature-icon">🔄</div>
        <h3>协同运行</h3>
        <p>不同技术栈的应用可以在同一平台上协同运行，无缝切换。</p>
      </div>
    </div>

    <div class="applications-section">
      <h3>可用应用</h3>
      <div class="app-cards">
        <router-link to="/micro-dashboard" class="app-card">
          <div class="app-icon">📊</div>
          <h4>仪表盘</h4>
          <p>数据可视化与统计分析</p>
        </router-link>

        <div class="app-card" @click="handleAuthClick">
          <div class="app-icon">🔐</div>
          <h4>认证中心</h4>
          <p>用户登录、注册与权限管理</p>
        </div>

        <router-link to="/micro-user" class="app-card">
          <div class="app-icon">👥</div>
          <h4>用户管理</h4>
          <p>用户信息与账号管理</p>
        </router-link>

        <router-link to="/legacy" class="app-card">
          <div class="app-icon">📱</div>
          <h4>传统应用</h4>
          <p>已有的Vue 2应用</p>
        </router-link>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted } from 'vue'
import { setGlobalState, getCurrentState } from '../global-state'
import { useRouter } from 'vue-router'
import { getToken } from '@shared/api'

const router = useRouter()

onMounted(() => {
  // 设置面包屑
  setGlobalState({
    breadcrumb: [
      { name: '首页', path: '/home' }
    ]
  })
})

// 处理认证中心点击事件
const handleAuthClick = (event: Event) => {
  const token = localStorage.getItem('micro-app-token')
  // 检查用户是否已经登录
  if (token) {
    alert('您已经登录认证，无需二次认证')
    return
  }
  router.push('/micro-auth')
}
</script>

<style scoped>
.home-container {
  max-width: 1200px;
  margin: 0 auto;
}

.welcome-section {
  text-align: center;
  padding: 60px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 12px;
  margin-bottom: 40px;
}

.welcome-section h2 {
  font-size: 2.5rem;
  margin-bottom: 16px;
  font-weight: 600;
}

.welcome-section p {
  font-size: 1.1rem;
  max-width: 950px;
  margin: 0 auto;
  opacity: 0.9;
}

.features-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
  margin-bottom: 60px;
}

.feature-card {
  background: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  text-align: center;
  transition: transform 0.3s, box-shadow 0.3s;
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.feature-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
}

.feature-card h3 {
  font-size: 1.3rem;
  margin-bottom: 12px;
  color: #333;
}

.feature-card p {
  color: #666;
  line-height: 1.6;
}

.applications-section h3 {
  text-align: center;
  font-size: 1.8rem;
  margin-bottom: 30px;
  color: #333;
}

.app-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 24px;
}

.app-card {
  display: block;
  background: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  text-align: center;
  text-decoration: none;
  color: inherit;
  transition: all 0.3s;
  border: 2px solid transparent;
}

.app-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  border-color: #1890ff;
}

.app-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.app-card h4 {
  font-size: 1.2rem;
  margin-bottom: 8px;
  color: #333;
}

.app-card p {
  color: #666;
  font-size: 0.95rem;
}

@media (max-width: 768px) {
  .welcome-section h2 {
    font-size: 2rem;
  }

  .features-section,
  .app-cards {
    grid-template-columns: 1fr;
  }
}
</style>